<?php

namespace Home\Model;

use Think\Model;

class AccountModel extends Model {

    protected $tableName = 'user';

    /**
     * 检查是否存在
     * @param type $email
     * @return type
     */
    function checkAccount($email) {
        $where = array('email' => $email);
        return $this->where($where)->count();
    }

    /**
     * 注册账号
     * @param type $data
     * @return type
     */
    function addUser($data) {
        return $this->add($data);
    }

    /**
     * 登陆检查
     * @param type $email
     * @param type $password
     * @return type
     */
    function checkLogin($email, $password) {
        $where = array(
            'email' => $email,
            'password' => md5($email . $password)
        );
        return $this->where($where)->find();
    }

    /**
     * 修改密码
     * @param type $email
     * @param type $data
     * @return type
     */
    function modifyPassword($email, $data) {
        $where = array('email' => $email);
        return $this->where($where)->save($data);
    }

    function getOneUser($where) {
        return $this->where($where)->find();
    }

}
